package com.baymax.test.scene.demo

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.PackageManager.MATCH_ALL
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.baymax.test.scene.BaseScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.newSceneFlexContainer

class OpenIQYScene : BaseScene() {
    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
        return p1.newSceneFlexContainer {
            //{appId='', packageName='com.gitv.tv.launcher', className='', version='3435', appid='',
            // action='com.gitv.tv.launcher.activity.GitvInterfaceActivity', apkUrl='',
            // appName='银河影视', forceUpdate='1', appExt='', appActionType='INSTALL',
            // extParams='', params=[{type=16, url=https://jscmcc-online-h5.gitv.tv/?screenId=-4293}], outerApkUrl='', neadUpdate=0, nativeApp=0, jsonStirng=''}
            val i = Intent()
//            i.setPackage("com.gitv.tv.launcher")
            i.action = "com.gitv.tv.launcher.activity.GitvInterfaceActivity"
            i.putExtra("type", "16")
            i.putExtra("url", "https://jscmcc-online-h5.gitv.tv/?screenId=-4293")
            println("intent $i")
            addButton("queryIntentActivities") {
               kotlin.runCatching {
                   var resolveinfoList = context.packageManager.queryIntentActivities(i, 0)
                   println("queryIntentActivities $resolveinfoList")
                   resolveinfoList = context.packageManager.queryIntentActivities(i, MATCH_ALL)
                   println("queryIntentActivities $resolveinfoList")
                   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                       resolveinfoList = context.packageManager.queryIntentActivities(
                           i,
                           PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_ALL.toLong())
                       )
                       println("queryIntentActivities2 $resolveinfoList")
                   }
               }.onFailure {
                   it.printStackTrace()
               }
            }

            addButton("open") {
               kotlin.runCatching {
                   context.startActivity(i)
               }.onFailure {
                   it.printStackTrace()
               }
            }

        }
    }
}
